package model;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

public class ListviewHistoricalincomeAdapter extends RecyclerView.Adapter<ListviewHistoricalincomeAdapter.HistoryVH> {

    private List<ListviewHistoricalincomeBean> mData;//数据

    private Context context;//上下文

    public ListviewHistoricalincomeAdapter(Context context) {
        this.mData = new ArrayList<>();
        this.context = context;
    }

    public void setupData(List<ListviewHistoricalincomeBean> data) {
        mData.clear();
        if (data != null) {
            mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public HistoryVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new HistoryVH(LayoutInflater.from(context).inflate(R.layout.listviewhistoricalincome_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull HistoryVH holder, int position) {
        if (position < 0 || position >= mData.size()) {
            return;
        }
        ListviewHistoricalincomeBean bean = mData.get(position);
        holder.textView1.setText(bean.getName1());
        holder.textView2.setText(bean.getName2());
        holder.textView3.setText(bean.getName3());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class HistoryVH extends RecyclerView.ViewHolder {
        private TextView textView1, textView2, textView3;

        public HistoryVH(@NonNull View itemView) {
            super(itemView);
            textView1 = itemView.findViewById(R.id.historicalincome_txt1);
            textView2 = itemView.findViewById(R.id.historicalincome_txt2);
            textView3 = itemView.findViewById(R.id.historicalincome_txt3);
        }
    }

    private class ViewHolder {
        TextView textView1, textView2, textView3;
    }

}
